package com.atguigu.dw.gmallpublisher.esdsl

/**
 * description ：订单详情表 es dsl 语句
 * author      ：剧情再美终是戏 
 * mail        : 13286520398@163.com
 * date        ：Created in 2020/2/20 20:40
 * modified By ：
 * version:    : 1.0
 */
object SaleDetailDsl {

  def getSaleDetailAndAggResultByAggFieldDsl(date: String,
                                             keyword: String,
                                             startPage: Int,
                                             size: Int,
                                             aggField: String,
                                             aggSize: Int): String = {
    s"""
       |{
       |  "from": ${(startPage - 1) * size},
       |  "size": ${size},
       |  "query": {
       |    "bool": {
       |      "filter": {
       |        "term": {
       |        "dt": "${date}"
       |      }},
       |      "must": [
       |       {
       |         "match": {
       |           "sku_name": {
       |             "query": "${keyword}",
       |             "operator": "and"
       |           }
       |         }
       |       }
       |      ]
       |    }
       |  },
       |  "aggs": {
       |    "groupby_${aggField}": {
       |      "terms": {
       |        "field": "${aggField}",
       |        "size": ${aggSize}
       |      }
       |    }
       |  }
       |}
       |""".stripMargin
  }
}
